package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.EventAttenderSO;

@Entity
@Table(name = "EVENT_ATTENDER", uniqueConstraints = @UniqueConstraint(columnNames = {"USER_ID", "EVENT_ID" }))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class EventAttender extends AbstractBaseModel {

	private static final long serialVersionUID = 1L;
	
	@ManyToOne
	@JoinColumn(name = "EVENT_ID", nullable = false)
	private Event event;
	
	@ManyToOne
	@JoinColumn(name = "USER_ID", nullable = false)
	private User user;
	
	public EventAttenderSO convertToServiceObject(String... ignoreProperties) {
		EventAttenderSO so = (EventAttenderSO) convert(new EventAttenderSO(),
				(String[]) ArrayUtils.addAll(ignoreProperties,new String[]{"event","user"}));
		so.setUser(this.user.convertToServiceObject());
		so.setEvent(this.event.convertToServiceObject(new String[]{"moderators", "posts","community","service","goods"}));
		return so;
	}

	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String toString() {
		return "EventAttender [event=" + event + ", user=" + user + "]";
	}
	
	

}
